package com.kehutong.common.excel.listener;

import com.alibaba.excel.annotation.ExcelProperty;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * 表头错误策略
 * @author jian Ye
 */
@SuppressWarnings("rawtypes")
public class BindTransfer {

    @SuppressWarnings("unchecked")
    public static<T> String castFieldName(Class<T> clazz) {
        Field[] declaredFields = clazz.getDeclaredFields();
        StringBuilder sb = new StringBuilder();
        for (Field field : declaredFields) {
            if (!field.isAnnotationPresent(ExcelProperty.class)) {
                continue;
            }
            ExcelProperty bindFieldName = field.getAnnotation(ExcelProperty.class);
            String[] value = bindFieldName.value();
            String fieldName;
            if(value.length>=2){
                fieldName = bindFieldName.value()[1];
            }else {
                fieldName = bindFieldName.value()[0];
            }
            sb.append("请确认【").append(fieldName).append("】列表头是否存在\n");
        }
        return sb.toString();
    }

}